package com.example.test_event_and_callback.infras.event;

import com.example.test_event_and_callback.infras.event.BaseEventDto;
import com.example.test_event_and_callback.infras.event.CallableEvent;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * @author Song Dan Yang
 * Description: </br>
 * date: 2023/11/21 16:33
 */
@Component
public class CallableEventPublisher {

    @Resource
    private ApplicationEventPublisher eventPublisher;

    public <T extends BaseEventDto> T publishEvent(CallableEvent<T> event) {
        event.setCallBackThread(Thread.currentThread());
        eventPublisher.publishEvent(event);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ignored) {

        }
        return event.getDto();
    }
//    @Override
//    public void publishEvent(ApplicationEvent event) {
//        ApplicationEventPublisher.super.publishEvent(event);
//    }

//    @Override
//    public void publishEvent(Object event) {
//
//    }
}
